local choujin = fk.CreateSkill{
  name = "wk_heg__choujin",
}

Fk:loadTranslationTable{
  ["wk_heg__choujin"] = "筹进",
  [":wk_heg__choujin"] = "当你的攻击范围增加后，你可以对一名其他角色造成1点伤害。", --注：这里忽略吴六剑，只考虑换刀和君刘备
  ["#wk_heg__choujin_choose"] = "筹进：选择一名其他角色，对其造成1点伤害",

  ["$wk_heg__choujin1"] = "预则立，不预则废！",
  ["$wk_heg__choujin2"] = "就用你，给我军祭旗！",
}

choujin:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(choujin.name) then return false end
      local goin_equip_attack = 0
      local goout_equip_attack = 1
      for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerEquip then
        for _, info in ipairs(move.moveInfo) do
          if table.contains({Card.SubtypeWeapon}, Fk:getCardById(info.cardId).sub_type) then
            goin_equip_attack = Fk:getCardById(info.cardId).attack_range
          end
        end
      end
      if move.from == player and move.fromArea == Card.PlayerEquip then
        for _, info in ipairs(move.moveInfo) do
          if table.contains({Card.SubtypeWeapon}, Fk:getCardById(info.cardId).sub_type) then
            goout_equip_attack = Fk:getCardById(info.cardId).attack_range
          end
        end
      end
    end
    return goin_equip_attack > goout_equip_attack
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return p ~= player end)
    if #targets > 0 then
      local tos = room:askToChoosePlayers(player, {
        targets = targets, 
        min_num = 1,
        max_num = 1,
        prompt = "#wk_heg__choujin_choose",
        skill_name = choujin.name,
        cancelable = false,
      })
      local to = tos[1]
      room:damage{
        from = player,
        to = to,
        damage = 1,
        skillName = choujin.name,
      }
    end
  end,
})

choujin:addEffect(fk.GeneralRevealed, {
  can_trigger = function (self, event, target, player, data)
    local room = player.room
    if not player:hasSkill(choujin.name) then return false end
    if event == fk.GeneralRevealed then
      if player == target then
        for _, v in pairs(data) do
          if table.contains(Fk.generals[v]:getSkillNameList(), "hs__firebow") then 
            return table.find(room.alive_players, function (p) return p:hasSkill("shouyue") end)
          end
        end
      else
        for _, v in pairs(data) do
          if table.contains(Fk.generals[v]:getSkillNameList(), "shouyue") then 
            return player:hasShownSkill("hs__firebow") or player:hasSkill("xuanhur__hs__firebow")
          end
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return not player:inMyAttackRange(p) end)
    if #targets > 0 then
      local tos = room:askToChoosePlayers(player, {
        targets = targets, 
        min_num = 1,
        max_num = 1,
        prompt = "#wk_heg__choujin_choose",
        skill_name = choujin.name,
        cancelable = false,
      })
      local to = tos[1]
      room:damage{
        from = player,
        to = to,
        damage = 1,
        skillName = choujin.name,
      }
    end
  end,
})

choujin:addEffect(fk.EventAcquireSkill, {
  can_trigger = function (self, event, target, player, data)
    local room = player.room
    if not player:hasSkill(choujin.name) then return false end
    return player == target and data.name == "xuanhur__hs__firebow" and 
        table.find(room.alive_players, function (p) return p:hasSkill("shouyue") end)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return not player:inMyAttackRange(p) end)
    if #targets > 0 then
      local tos = room:askToChoosePlayers(player, {
        targets = targets, 
        min_num = 1,
        max_num = 1,
        prompt = "#wk_heg__choujin_choose",
        skill_name = choujin.name,
        cancelable = false,
      })
      local to = tos[1]
      room:damage{
        from = player,
        to = to,
        damage = 1,
        skillName = choujin.name,
      }
    end
  end,
})

return choujin